pull: Always scan for commit object, even if ref is unchanged
authorColin Walters <walters@verbum.org>
Tue, 23 Jul 2013 23:36:15 +0000 (19:36 -0400)
committerColin Walters <walters@verbum.org>
Tue, 23 Jul 2013 23:36:15 +0000 (19:36 -0400)
If the admin encounters corruption and does:

$ ostree admin fsck --delete

We want them to be able to recover the objects easily from the
network; with this patch, they do:

$ ln -s dummyvalue /ostree/repo/transaction
$ ostree refs --delete remotename:branchname
$ ostree pull remotename

This patch avoids the need for the refs --delete; we might as well
force scan the commit, and with this patch we still print that it
changed.

src/libostree/ostree-repo-pull.c

index 9f38ed363c78f4040bc7c6d6ac6035367a32c340..a270d1c044872e44b79b0c2554e96db18198423e 100644 (file)
@@ -1356,24 +1356,11 @@ ostree_repo_pull (OstreeRepo               *repo,
       gs_free char *key = NULL;
       gs_free char *remote_ref = NULL;
       gs_free char *baseurl = NULL;
-      gs_free char *original_rev = NULL;
-
-      remote_ref = g_strdup_printf ("%s/%s", pull_data->remote_name, ref);
 
-      if (!ostree_repo_resolve_rev (pull_data->repo, remote_ref, TRUE, &original_rev, error))
-        goto out;
-
-      if (original_rev && strcmp (sha256, original_rev) == 0)
-        {
-          g_print ("No changes in %s\n", remote_ref);
-        }
-      else
-        {
-          ot_waitable_queue_push (pull_data->metadata_objects_to_scan,
-                                  pull_worker_message_new (PULL_MSG_SCAN,
-                                                           ostree_object_name_serialize (sha256, OSTREE_OBJECT_TYPE_COMMIT)));
-          g_hash_table_insert (updated_refs, g_strdup (ref), g_strdup (sha256));
-        }
+      ot_waitable_queue_push (pull_data->metadata_objects_to_scan,
+                              pull_worker_message_new (PULL_MSG_SCAN,
+                                                       ostree_object_name_serialize (sha256, OSTREE_OBJECT_TYPE_COMMIT)));
+      g_hash_table_insert (updated_refs, g_strdup (ref), g_strdup (sha256));
     }
   
   {
@@ -1401,13 +1388,24 @@ ostree_repo_pull (OstreeRepo               *repo,
       const char *ref = key;
       const char *checksum = value;
       gs_free char *remote_ref = NULL;
+      gs_free char *original_rev = NULL;
           
       remote_ref = g_strdup_printf ("%s/%s", pull_data->remote_name, ref);
-          
-      if (!ostree_repo_write_ref (pull_data->repo, pull_data->remote_name, ref, checksum, error))
+
+      if (!ostree_repo_resolve_rev (pull_data->repo, remote_ref, TRUE, &original_rev, error))
         goto out;
           
-      g_print ("remote %s is now %s\n", remote_ref, checksum);
+      if (original_rev && strcmp (checksum, original_rev) == 0)
+        {
+          g_print ("remote %s is unchanged from %s\n", remote_ref, original_rev);
+        }
+      else
+        {
+          if (!ostree_repo_write_ref (pull_data->repo, pull_data->remote_name, ref, checksum, error))
+            goto out;
+          
+          g_print ("remote %s is now %s\n", remote_ref, checksum);
+        }
     }
       
   end_time = g_get_monotonic_time ();